<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\HospitalInfo;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class HospitalInfoController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new HospitalInfo(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('banner');
            $grid->column('title_logo');
            $grid->column('tel');
            $grid->column('description');
            $grid->column('address');
            $grid->column('open_date');
            $grid->column('lng');
            $grid->column('lat');
            $grid->column('images');
            $grid->column('lines');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new HospitalInfo(), function (Show $show) {
            $show->field('id');
            $show->field('banner');
            $show->field('title_logo');
            $show->field('tel');
            $show->field('description');
            $show->field('address');
            $show->field('open_date');
            $show->field('lng');
            $show->field('lat');
            $show->field('images');
            $show->field('lines');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new HospitalInfo(), function (Form $form) {
            $form->list('banner')
                ->help('大约376*200的图片')
                ->required();
            $form->image('title_logo')
                ->autoUpload()
                ->uniqueName()
                ->removable(false)
                ->help('请上传大约376*60的图片')
                ->required();
            $form->text('tel')
                ->required();
            $form->text('open_date')
                ->required();
            $form->text('address')
                ->required();
            $form->text('lng')
                ->required();
            $form->text('lat')
                ->required();
            $form->textarea('description')
                ->required();

            $form->table('images', function ($table) {
                $table->text('title', '名称');
                $table->image('image', '图片')
                    ->autoUpload()
                    ->uniqueName()
                    ->removable(false)
                    ->help('请上传大约350*180的图片');
            })->saving(function ($v) {
                return json_encode($v);
            });

            $form->table('lines', function ($table) {
                $table->image('title', '标题图片')
                    ->autoUpload()
                    ->uniqueName()
                    ->removable(false)
                    ->help('请上传大约347*33的图片')
                    ->required();
                $table->editor('routers');
            })->saving(function ($v) {
                return json_encode($v);
            });


            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
